<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue</title>
</head>

<body>
  <div id="app">
    <!-- <h1>{{msg}}</h1>
        <p>{{helloMsg}}</p> -->
  </div>
  <script src="../dist/vue.js"></script>
  <script>
    // 测试父子组件生命周期调用顺序
    // 父created > 子created > 子mounted > 父mounted
    // 子updated > 父updated
    let v = new Vue({
      el: '#app',
      template: `<div>
                    <myaccount></myaccount>
                    <ul
                    :class="bindCls"
                    class="list"
                    v-if="isShow">
                        <li v-for="(item,index) in list" @click="clickItem(index)"> {{item}}: {{index}}</li>
                    </ul></div>`,
      components: {
        'myaccount': {
          template: "<div>hello sub {{name}} <abc></abc></div>",
          data() {
            return {
              name: "myaccount"
            }
          },
          created() {
            console.log("created out");
          },
          mounted() {
            const self = this;
            setTimeout(() => {
              self._data.name = "new account";
            }, 2000)
            console.log("mounted out");
          },
          updated() {
            console.log("updated out");
          },
          components: {
            "abc": {
              template: "<p> - span -{{msg}} </p>",
              data() {
                return {
                  msg: "hello"
                }
              },
              created() {
                console.log("created inner");
              },
              mounted() {
                const self = this;
                setTimeout(() => {
                  self._data.msg = "world";
                }, 2000)
                console.log("mounted inner");
              },
              updated() {
                console.log("updated inner");
              },
            },

          }
        }
      },
      data() {
        return {
          msg: 'Hello',
          isShow: true,
          bindCls: 'demo',
          list: [{
            index: 1,
            value: 'a'
          }, {
            index: 2,
            value: 'b'
          }, {
            index: 3,
            value: 'c'
          }]
        }
      },
      computed: {
        helloMsg() {
          return this.msg + 'world!'
        }
      },
      methods: {
        clickItem(idx) {
          console.log(idx);
        }
      }
    });
    console.log(v);

  </script>
</body>

</html>
